var smileys = new Array()
smileys[0] = new Array();
smileys[0][0] = Array(':-)',':)');
smileys[0][1] = 'smile.png';
smileys[1] = new Array();
smileys[1][0] = Array(':-P',':P');
smileys[1][1] = 'tongue.png';
smileys[2] = new Array();
smileys[2][0] = Array(':-S',':S');
smileys[2][1] = 'confused.png';
smileys[3] = new Array();
smileys[3][0] = Array(':\'(',':~(');
smileys[3][1] = 'cry.png';
smileys[4] = new Array();
smileys[4][0] = Array(':-D',':D');
smileys[4][1] = 'biggrin.png';
smileys[5] = new Array();
smileys[5][0] = Array(':-(',':(');
smileys[5][1] = 'sad.png';
smileys[6] = new Array();
smileys[6][0] = Array(':-*',':*');
smileys[6][1] = 'kiss.png';
smileys[7] = new Array();
smileys[7][0] = Array(';-)',';)');
smileys[7][1] = 'wink.png';
smileys[8] = new Array();
smileys[8][0] = Array(':-$',':$');
smileys[8][1] = 'blush.png';

function smilify(buf, pref)
{
        var ret;
        for (var i = 0; i < smileys.length; i++)
        {
                for (s in smileys[i][0])
                {
			smiley = smileys[i][0][s]
			while (buf.indexOf(smiley) != -1)
				buf = buf.replace(smiley, '<img src="' + pref + '/smileys/' + smileys[i][1] + '" />');
                }
        }
        return buf;
}


function abreSmileys(evt, context, url)
{
	if($("#"+context+"_div_smileys").length == 0)
	{
		var contexto = $("#"+context).find("textarea");
		var html = '';

		$(smileys).each(function(i, a){
			strAlt = "";
			
			if(a[0].length > 0)
			{
				for(j = 0; j < a[0].length; j ++)
					strAlt += a[0][j]+" ";
			}

			html += '<input type="image" src="'+url+a[1]+'" style="border:1px #f1f1f1 solid; padding:2px;" alt="'+(strAlt)+'" onclick="$(\'#'+context+'_div_smileys\').remove(); $(\'#'+context+'\').find(\'textarea\').css(\'visibility\', \'visible\'); $(\'textarea\', \'#'+context+'\').replaceSelection(\''+a[0][0]+'\', true);" />'
		});

		$("<div></div>")
		.attr("id", context+"_div_smileys")
		.css({
			background: '#ffffff',
			width: contexto.width(),
			height : contexto.height() - 5
		})
		.append(html)
		.insertBefore(contexto);

		contexto.css("visibility", "hidden");
	}else
	{
		$('#'+context+'_div_smileys').remove(); 
		$('#'+context).find('textarea').css('visibility', 'visible')
	}
}